package Servlet;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;

import Service.InfoService;
import ServiceImpl.InfoServiceImpl;

/**
 * Servlet implementation class AddInfoServlet
 */
public class AddInfoServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
    
    public AddInfoServlet() {}
    
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		this.doPost(request, response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
		response.setContentType("text/html charset = UTF-8");
		InfoService infoService = new InfoServiceImpl();
		String car_id = request.getParameter("car_id");
		String time = request.getParameter("time");
		String addType = request.getParameter("addType");
		switch(addType) {
		case "1":
			infoService.insert(car_id, time, null);
			System.out.println(time);
			break;
		case "2":
			infoService.insert(car_id, null, time);
			break;
		default:
			break;
		}
		
		request.getRequestDispatcher("add_info_of_car.jsp").forward(request, response);
	}
}
